<template>
  <div id="app">
    <h2>测试题</h2>
    <div class="subject">
      <subject-item
        v-for="(obj, index) in list"
        :key="index"
        :subjectObj="obj"
        :i="index"
        @update="update"
        />
    </div>
    <div class="result" style="display: flex;">
      <result-item
        v-for="(item, index) in list"
        :key="index"
        :subjectItem="item"
        :i="index"
        />
    </div>
  </div>
</template>

<script>
import SubjectItem from './components/SubjectItem'
import ResultItem from './components/ResultItem'
function getRandom(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min
}
const list = []
for(let i = 0; i < 5; i++) {
  let num1 = getRandom(1, 10)
  let num2 = getRandom(1, 10)
  list.push({
    num1,
    num2,
    answer: num1 + num2,
    isDone: false,
    isRight: false
  })
}

export default {
  data() {
    return {
      list
    }
  },
  components: { SubjectItem, ResultItem},
  methods: {
    update({ index, result }) {
      this.list[index].isRight = result
      this.list[index].isDone = true
    }
  }
};
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>